<?php

namespace App\Http\Controllers\Backend\Setting;

use App\Events\SettingLogEvent;
use App\Http\Requests\Backend\Setting\SettingHintRequest;
use App\Models\SettingChannel;
use App\Models\SettingHint;
use App\Models\SettingLog;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SettingHintController extends Controller
{
    use \App\Library\Traits\SettingLog;
    const SETTING_TABLE = 'setting_hints';
    public function __construct()
    {
        $this->middleware('auth:backend');
        $this->user = auth('backend')->user();
    }

    public function getHint(){

        $settingHint  = new SettingHint();
        $settingHint->setConnection('backend');
        $info = $settingHint->getHintList();
        return success($info);
    }

    public function setHint(SettingHintRequest $request,$id){
        $content = $request->input('content','');
        $status = $request->input('status','');
        $data = $request->all();

        if ((!empty($content)) && (!empty($status))) {
            $result = SettingHint::where('id',$id) -> update(['content' => $content,'status' => $status]);
        }elseif ((!empty($status)) && (empty($content))){
            $result = SettingHint::where('id',$id) -> update(['status' => $status]);
        }elseif ((empty($status)) && (!empty($content))){
            $result = SettingHint::where('id',$id) -> update(['content' => $content]);
        }else{
            return failed('设置失败');
        }
        if($result){
            $this->setting_log($this->user->id,self::SETTING_TABLE,$id,SettingLog::LOG_UPDATE,$data);
            return updated('');
        }else{
            return failed('设置失败');
        }
    }
}
